home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / comm / irc / epic4-mos.lha / share / epic / script / map < prev    next >
Text File  |  2002-09-18  |  3KB  |  113 lines

  1. # map script.  lifted from anduril by wd.
  2. # this script is in the public domain
  3.  
  4. # $Id: map,v 1.1 2002/07/31 23:39:35 wd Exp $
  5.  
  6. # here's how it works.  we retrieve links from the server using a /links
  7. # command.  we then sort them out into an array as below, and then iterate
  8. # over the array to generate the map.  on servers with 005 support and the
  9. # map token, we simply use their map command unless mapping from a specific
  10. # server is requested.
  11.  
  12. alias map.encode {return $encode($tolower($*))}
  13.  
  14. alias map.retrieve_links {
  15.     ^on ^364 * {
  16.     @:client = [$1]
  17.     @:hub = [$2]
  18.     @:hops = [$3]
  19.     @:gecos = [$4-]
  20.  
  21.     @map.links.all #= [$client ]
  22.     @:henc = map.encode($hub)
  23.     @:cenc = map.encode($client)
  24.     @map.links[$cenc][hub] = hub
  25.     @map.links[$cenc][hops] = hops
  26.     @map.links[$cenc][info] = gecos
  27.     if (hops == 0) {
  28.         return
  29.     }
  30.  
  31.     @push(map.links[$cenc][servers] $hub)
  32.     @push(map.links[$henc][servers] $client)
  33.     }
  34.     ^eval on ^365 "*" map.finish_links $*
  35.     //^links
  36. }
  37.  
  38. alias map.finish_links {
  39.     ^on 364 -"*"
  40.     ^on 365 -"*"
  41.     for xx in ($map.links.all) {
  42.     @:senc = map.encode($xx)
  43.     @map.links[$senc][servers] = uniq($map.links[$senc][servers])
  44.     if (numwords($map.links[$map.encode($xx)][servers]) > 1) {
  45.         @push(map.links.hubs $xx)
  46.     }
  47.     }
  48.     # sort our hubs by distance in hops
  49.     @:hops = 0
  50.     @:newlist = []
  51.     while (sort($newlist) != sort($map.links.hubs)) {
  52.     @:new = []
  53.     for xx in ($map.links.hubs) {
  54.         if (map.links[$map.encode($xx)][hops] == hops) {
  55.         @push(:new $xx)
  56.         }
  57.     }
  58.     if (new != []) {
  59.         @push(:newlist $new)
  60.     }
  61.     @:hops++
  62.     }
  63.     @map.links.hubs = newlist
  64.     $*
  65.     fe ($aliasctl(assign pmatch map.links*)) xx {
  66.     ^assign -$xx
  67.     }
  68. }
  69.  
  70. alias map (server) {
  71.     if (serverctl(GET $servernum() 005 MAP) != [] && server == []) {
  72.     quote map
  73.     return
  74.     }
  75.     map.retrieve_links map.exec $server
  76. }
  77.  
  78. ### this displays a single branch of a map.  I changed this alias slightly (to
  79. ### make it work properly) after observing the way Liandrin's script worked.
  80. alias map.map_branch (server, prefix) {
  81.     @push(map.links.seen $server)
  82.     @:senc = map.encode($server)
  83.     echo [map] $prefix$server \($map.links[$senc][hops] $map.links[$senc][info]\)
  84.     @:servers = remws($map.links.seen / $map.links[$senc][servers])
  85.     if (numwords($servers) == 0) {
  86.     return
  87.     }
  88.     @:prefix = msar(/`-/  /-/ /$prefix)
  89.  
  90.     for xx in ($servers) {
  91.     if (xx == rightw(1 $servers)) {
  92.         map.map_branch $xx $prefix`-
  93.     } else {
  94.         map.map_branch $xx $prefix|-
  95.     }
  96.     }
  97. }
  98.  
  99.  
  100. alias map.exec (server) {
  101.     if (server == []) {
  102.     @:server = builtin_expando(S)
  103.     }
  104.  
  105.     if (findw($server $map.links.all) == -1) {
  106.     aerrecho server $server does not appear to be online
  107.     return
  108.     }
  109.     map.map_branch $server
  110. }
  111.     
  112. ### vi:set ts=8 sts=4 sw=4 tw=79 syntax=off ai smartindent:
  113.